package newcoder_exp.justPractise;

import org.junit.Test;

public class NC106 {
    public class Solution {
        /**
                if (A[i] > max) {
                    third = second;
                    second = max;
                    max = A[i];
                }
                if (A[i] < min) {
                    prior = min;
                    min = A[i];
                }
         */
        public long solve (int[] A) {
    //         int max = Integer.MIN_VALUE, second = max, min = Integer.MAX_VALUE, prior = min, third = max;
            int max = 0, second = max, min = 0, prior = min, third = max;
            for (int i = 0; i < A.length; i++) {
                if (A[i] > A[max]) {
                    max = i;
                }
                if (A[i] < A[min]) {
                    min = i;
                }
            }
            for (int i = 0; i < A.length; i++) {
                if (A[i] > A[second] && i != max) {
                    second = i;
                }
                if (A[i] < A[prior] && min != i) {
                    prior = i;
                }
            }
              for (int i = 0; i < A.length; i++) {
                if (A[i] > A[third] && i != max && i != second) {
                    third = i;
                }
              }
            System.out.println(max + "" + second + "" + third);
            return Math.max(A[max] * A[second] * A[third], 
                            A[min] * A[prior] * A[max]);
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{3,4,-1,-2};
        s.solve(nums);
    }
}
